package org.wechat4j.api;

import org.wechat4j.config.ApiConfig;
import org.wechat4j.exception.MpInvokeException;
import org.wechat4j.model.Response;
import org.wechat4j.utils.Https;
import org.wechat4j.utils.ResponseUtils;

import java.util.List;

/**
 * @author bjliuyong
 * @version 1.0
 * @created date 16-11-18
 */
public final class GetIpService  {

    private static final String getCallBackIpUrl = ApiConfig.baseUrl + "getcallbackip?access_token=";

    /**
     * 获取微信服务器IP地址
     *
     * 如果公众号基于安全等考虑，需要获知微信服务器的IP地址列表，以便进行相关限制，可以通过该接口获得微信服务器IP地址列表或者IP网段信息。
     *
     * @param accessToken
     * @return
     */
    public static List<String> getCallbackIp(String accessToken) throws MpInvokeException{
        String requestUrl =  getCallBackIpUrl + accessToken ;
        String content    = Https.get(requestUrl , null ) ;
        return ((IpList) ResponseUtils.parse(content , IpList.class)).ip_list;
    }

    static class IpList extends Response {
        public List<String> ip_list;
    }
}
